//
//  ViewController.m
//  10801A
//
//  Created by student on 16/2/23.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIPickerViewDataSource,UIPickerViewDelegate>
@property (nonatomic,strong) NSArray *leftlist;
@property (nonatomic,strong) NSArray *rightlist;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.picker.dataSource = self;
    self.picker.delegate = self;
    
    
    self.leftlist = @[@"花生酱",@"金枪鱼",@"沙拉酱",@"烤牛肉",@"蔬菜",@"火鸡"];
    self.rightlist = @[@"酸面包",@"黑麦面包",@"天然有机谷",@"粗面粉面包",@"白面包"];
    
    
    // Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)Btn:(id)sender
{
    int sel1 = [self.picker selectedRowInComponent:0];
    int sel2 = [self.picker selectedRowInComponent:1];
    
    self.infolabel.text = [NSString stringWithFormat:@"我今天吃了%@%@",self.leftlist[sel1],self.rightlist[sel2]];
    NSString *str1 = [NSString stringWithFormat:@"%@%@",self.leftlist[sel1],self.rightlist[sel2]];
    UIAlertView *AlertView = [[UIAlertView alloc]initWithTitle:@"我今天吃了" message:str1 delegate:nil cancelButtonTitle:@"重新选择" otherButtonTitles:@"确定", nil];
    [AlertView show];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 2;
}

// 第几列有几行?
- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{
    if(component == 0)
    {
        return self.leftlist.count;
    }
    else
    {
        return self.rightlist.count;
    }
}

// 第几行第几列是什么内容
- (nullable NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if(component == 0)
    {
        return self.leftlist[row];
    }
    else
    {
        return self.rightlist[row];
    }
}


// 触发的事件
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if(component == 0)
    {
        NSLog(@"当前你选择了%@",self.leftlist[row]);
    }
    else
    {
        NSLog(@"当前你选择了%@",self.rightlist[row]);    }
}




@end
